/*
 * @Author: 韩旭
 * @Date: 2021-08-17 16:34:19
 * @LastEditTime: 2021-09-08 17:30:56
 * @LastEditors: 韩旭
 * @Description:基于URL或者Crypto.getRandomValues生成UUID
 * @FilePath: \tvmscanner-front\plugins\utils\uuid.js
 */

// 36位uuid 带-
export function genUUID() {
    const url = URL.createObjectURL(new Blob([]))
    const uuid = url.substring(url.lastIndexOf('/') + 1)
    URL.revokeObjectURL(url)
    return uuid
  }
  
  // 最少8位随机uuid，可设置想要的长度
  export function generateRandomAlphaNum(len) {
    let rdmString = ''
    len = len || 8
    for (
      ;
      rdmString.length < len;
      rdmString += Math.random().toString(36).substr(2)
    );
    return rdmString.substr(0, len)
  }
  
  // 最少8位随机uuid，可设置想要的长度与
  export function uuid(length, chars) {
    chars =
      chars || '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    length = length || 8
    let result = ''
    for (let i = length; i > 0; --i)
      result += chars[Math.floor(Math.random() * chars.length)]
    return result
  }
  